package com.twt.config;

import com.twt.common.exceptions.AppException;
import com.twt.common.pojo.Result;
import com.twt.common.pojo.ResultCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.net.BindException;

@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    /**
     * @Description: 业务异常
     * @Author: TWT
     * @Date: 21:01 2022/6/18
     * @param:[e]
     * @return:com.twt.common.pojo.Result
     **/
    @ExceptionHandler(AppException.class)
    @ResponseBody
    public Result exceptionHandler(AppException e) {
        Result result = Result.fail(ResultCodeEnum.BIZ_ERROR.getCode(),e.getMessage());
        e.printStackTrace();
        return result;
    }
/*
    @ExceptionHandler(BindException.class)
    @ResponseBody
    public Result bindExceptionHandler(BindException e){

    }*/

}
